/*!
 * \file test_http.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"

#include "t_frreport_convert/t_frreport_convert.h"
#include "t_frreport_dbg/t_frreport_dbg.h"
#include "t_frreport_opt/t_frreport_opt.h"
void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(FR_MEM_BUFF_SIZE, "apmcomm") == FR_FAIL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    // t_frreport_convert
    add_suites(fun_suites, i_suites_len, add_suite___frreport_conver_double);
    add_suites(fun_suites, i_suites_len, add_suite___frreport_conver_header);
    add_suites(fun_suites, i_suites_len, add_suite___frreport_conver_l7data_list);
    add_suites(fun_suites, i_suites_len, add_suite___frreport_conver_llong);
    add_suites(fun_suites, i_suites_len, add_suite___frreport_conver_str);

    //t_frreport_dbg
    add_suites(fun_suites, i_suites_len, add_suite_frdbg_rename_filename);
    add_suites(fun_suites, i_suites_len, add_suite_frdbg_report_data_format);

    //t_frreport_opt
    add_suites(fun_suites, i_suites_len, add_suite_FrReportOpt_del_fieldAll);
    add_suites(fun_suites, i_suites_len, add_suite_FrReportOpt_del_fieldIndex);
    add_suites(fun_suites, i_suites_len, add_suite_FrReportOpt_get_existsField);
    add_suites(fun_suites, i_suites_len, add_suite_FrReportOpt_get_field);
    add_suites(fun_suites, i_suites_len, add_suite_FrReportOpt_get_fieldSize);


    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
